package com.ncr.travel.appmgr.client.mvp;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.event.shared.HandlerRegistration;

/**
 * 
 * @author ma250087
 * 
 */
public abstract class BasePresenter<V extends View> implements Presenter<V> {

	protected final EventBus eventBus;
	protected final V view;
	protected final List<HandlerRegistration> handlerRegistrations;

	public BasePresenter(final EventBus eventBus, final V view) {

		this.eventBus = eventBus;
		this.view = view;

		handlerRegistrations = new ArrayList<HandlerRegistration>();
	}

	public void bind() {
	}

	public void unbind() {

		for (HandlerRegistration reg : handlerRegistrations) {
			reg.removeHandler();
		}
		handlerRegistrations.clear();
	}

	public V getView() {
		return this.view;
	}

	protected void registerHandler(HandlerRegistration handlerRegistration) {
		handlerRegistrations.add(handlerRegistration);
	}

}
